<?php
namespace App\Http\Controllers\Find;
use Illuminate\Http\Request;
use App\Http\Controllers\BaseApiController;
use App\Services\Find\InfomationService;
use Illuminate\Support\Facades\Validator;
class InfomationController extends BaseApiController{
    private $service;
    public function __construct(InfomationService $service){
        //继承基类的构造方法
        parent::__construct();
        //依赖注入service
        $this->service=$service;
    }
    /**
     * 航运咨询列表
     */
    public function InfomationList(){
        //获取咨询列表
        $data=$this->service->InfomationList();
        return $data;
    }
    /**
     * 根据类型查询咨询
     */
    public function InfoType(Request $request){
        //验证类型参数是否为数字已经是否为空
        $validate = Validator::make($request->all(), [
            'type' => 'required|integer'
        ]);
        //返回错误信息
        if($validate->fails()) {
            return $validate->errors()->all();
        }
        $type=$request->get('type');
        if($type==0){
            return $this->InfomationList();
        }
        $data=$this->service->InfoType($type);
        return $data;
    }
    /**
     * 航运咨询详情
     */
    public function InfomationDesc(Request $request){
        //验证id参数是否为数字已经是否为空
        $validate = Validator::make($request->all(), [
            'id' => 'required|integer'
        ]);
        //返回错误信息
        if($validate->fails()) {
            return $validate->errors()->all();
        }
        $id=$request->get('id');
        $arr=$this->service->InfomationDesc($id);
        return $arr;
    }
}